//----------------------------------------------------------------------------------------------------------------
//			Filename:		Chapter2.h
//			  Author:		Adrian De Barro
//			    Date:		10/08/2015
//----------------------------------------------------------------------------------------------------------------
//			  Status:		Currently Building
//----------------------------------------------------------------------------------------------------------------

#include <exception>
#include <iostream>
#include <string>
#include <stdexcept>
#include <sstream>


using std::exception;
using std::string;
namespace Chapter2
{
	//----------------------------------------------------------------------------------------------------------------
	/**
	  *			  Class: My_Exception
	  */
	//----------------------------------------------------------------------------------------------------------------
	class My_Exception : public std::runtime_error
	{
		//private (by default in class)
		string msg;
	public:
		//----------------------------------------------------------------------------------------------------------------
		/**
		*				Name:	CONSTRUCTOR
		*		Return Value:	NULL
		*		  Parameters:   CURRENT COLOR
		*			  Status:	READY
		*/
		//----------------------------------------------------------------------------------------------------------------
		My_Exception(const string &arg, const char *file, int line):
		std::runtime_error(arg)
		{
			std::ostringstream output;
			output << file << ":" << line << arg;
			msg = output.str();
		}
		//----------------------------------------------------------------------------------------------------------------
		/**
		*				Name:	DESTRUCTOR : throws the created exception
		*		Return Value:	NULL
		*		  Parameters:   CURRENT COLOR
		*			  Status:	READY
		*/
		//----------------------------------------------------------------------------------------------------------------
		~My_Exception() throw() {}
		//----------------------------------------------------------------------------------------------------------------
		/**
		*				Name:	what: overloaded method
		*		Return Value:	NULL
		*		  Parameters:   CURRENT COLOR
		*			  Status:	READY
		*/
		//----------------------------------------------------------------------------------------------------------------
		const char *what() const throw()
		{
			return msg.c_str();
		}
		//----------------------------------------------------------------------------------------------------------------		
	};

	//----------------------------------------------------------------------------------------------------------------
	/**
	*				Name:	MACRO: THROW_LINE
	*		Return Value:	Fires exception
	*		  Parameters:   error
	*			  Status:	READY
	*/
	//----------------------------------------------------------------------------------------------------------------
	#define throw_line(arg) throw My_Exception(arg, __FILE__, __LINE__);
	//----------------------------------------------------------------------------------------------------------------		


}